package com.tsunami.authority.enums.admin;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tsunami.base.BaseEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 行业类型
 *
 * @author lx
 * @since 2021-12-02 17:46
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "行业类型-枚举")
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum MoldType implements BaseEnum {
    /**
     * EDU="education"
     */
    EDU("教育", "EDU"),
    /**
     * COM="company"
     */
    COM("企业/组织", "COM"),
    /**
     * MED="medicine"
     */
    MED("医药", "MED"),
    ;

    @Schema(description = "描述")
    private String desc;
    @Schema(description = "编码")
    private String code;

    public static MoldType match(String val, MoldType def) {
        for (MoldType enm : MoldType.values()) {
            if (enm.name().equalsIgnoreCase(val)) {
                return enm;
            }
        }
        return def;
    }

    public static MoldType get(String val) {
        return match(val, null);
    }

    public boolean eq(String val) {
        return this.name().equalsIgnoreCase(val);
    }

    public boolean eq(MoldType val) {
        if (val == null) {
            return false;
        }
        return eq(val.name());
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String getDesc() {
        return this.desc;
    }

    public static MoldType getEnum(String code) {
        for (final MoldType item : MoldType.values()) {
            if (item.code.equals(code)) {
                return item;
            }
        }
        return null;
    }
}
